#include "ulib.h"

CUString strip_pos( CUString &l )	{
	CUStringList ls;
	ls.TokenizeByChar( l, " " );

	CUString ret;
	ret += l;
	for( int i=0; i<ls.GetSize(); i++ )	{
		CUString tok = ls.GetAt(i);
		ret += tok.Left( tok.Find("/" ) ) + CUString(" ");
	}

	return ret;

}


bool func1( char *fn1, char *fn2, char *fn3, char *fnout )
{
	CUTextFile f1( fn1, "r" );
	CUTextFile f2( fn2, "r" );
	CUTextFile f3( fn3, "r" );

	CUTextFile fout( fnout, "w" );
	int num =0;
	while(1)	{
		CUString l1;
		CUString l2;
		CUString l3;
		if( f1.ReadLine( l1) == false ) break;
		if( f2.ReadLine( l2) == false ) break;
		if( f3.ReadLine( l3) == false ) break;
		num++;

		CUString l1_plain = strip_pos( l1 );
		CUString l2_plain = strip_pos( l2 );
		CUString l3_plain = strip_pos( l3 );

		if( l1.GetLength() > 150 )	continue;

		if( l1 != l2 && l2 != l3 && l3 != l1 )	{
			fprintf( fout.GetFP(), "[ALLDIFF] %d\n", num );
			fprintf( fout.GetFP(), "%s\n", l1.GetStr() );
			fprintf( fout.GetFP(), "%s\n", l2.GetStr() );
			fprintf( fout.GetFP(), "%s\n", l3.GetStr() );
			/*
			fprintf( fout.GetFP(), "%s\n", l1_plain.GetStr() );
			fprintf( fout.GetFP(), "%s\n", l2_plain.GetStr() );
			fprintf( fout.GetFP(), "%s\n", l3_plain.GetStr() );
			*/
		}
		if( l1 != l2 && l2 != l3 && l3 == l1 )	{
			fprintf( fout.GetFP(), "[BUTRECOV]\n" );
			fprintf( fout.GetFP(), "%s\n", l1.GetStr() );
			fprintf( fout.GetFP(), "%s\n", l2.GetStr() );
			fprintf( fout.GetFP(), "%s\n", l3.GetStr() );
		}
		 
	}

	return true;

}



int main( int argc, char *argv[] )
{
	if( argc != 5 )	{
		fprintf( stderr, "usage: snt-compare i0 i1 i2 out\n" );
		return 1;
	}

	if( func1( argv[1], argv[2], argv[3], argv[4]) == false )	{
		return 1;
	}

	return 0;
}

